<?php

// no direct access
defined('_JEXEC') or die;

jimport('joomla.plugin.plugin');

/**
 * Joomla! Full Page Background Plugin
 *
 * @package		Joomla.Plugin
 * @subpackage	System.fullpagebackground
 */
class plgSystemFullPageBackground extends JPlugin
{
	
		function onAfterInitialise()
		{
		$app = JFactory::getApplication();
		if ($app->isSite()) {
			
			require_once(dirname(__FILE__) . DS . 'includes' . DS . 'functions.php');
			if($this->params->get("disableMobileDevices") == 1) {
				require_once(dirname(__FILE__) . DS . 'includes' . DS . 'mobileDetect.php');
			}
			
			if($this->params->get("disableMobileDevices") == 1 && detect_mobile() == false){
					$doc =& JFactory::getDocument();
					$doc->addScript('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js');
					$doc->addScript('plugins' . DS . 'system' . DS . 'fullpagebackground' . DS . 'js' . DS . 'supersized.3.0.core.js');
					$doc->addStyleSheet('plugins' . DS . 'system' . DS . 'fullpagebackground' . DS . 'css' . DS . 'supersized.css');
					$baseURI = JURI::base();			
					if($this->params->get("randomImage") == 1) {
						$imagesPath = JPATH_BASE . '/images/' . $this->params->get("imagesFolder") . '';
						if(checkEmptyDirectory($imagesPath)) {
							$my_images = listImages($imagesPath, $this->params->get("minimumImageSize"), $this->params->get("minimumWidth"), $this->params->get("minimumHeight"));
							if(!(empty($my_images))) {
							$doc->addScriptDeclaration(assignImage($baseURI . implode(randomImage($my_images)), $this->params->get("displayCenter")));
							}
						} else {
							JFactory::getApplication()->enqueueMessage( JText::_( 'Background Image Folder is Empty!' ), 'error' );
						}
						
					} else {
						
						// Functionality for menu item designation to be added later.
						var_dump($params);
						
					
					}			
				}
				
				

			
	
		}
	
	}
	
	
	
}

?>